package com.cdtye.shuoh.service.rule.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdtye.shuoh.domain.rule.entity.RuleAlarmList;
import com.cdtye.shuoh.domain.rule.vo.RuleAlarmListVo;
import com.cdtye.shuoh.mapper.rule.RuleAlarmListMapper;
import com.cdtye.shuoh.service.rule.RuleAlarmListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class RuleAlarmListServiceImpl extends ServiceImpl<RuleAlarmListMapper, RuleAlarmList> implements RuleAlarmListService {

    @Autowired
    private RuleAlarmListMapper ruleAlarmListMapper;
    @Override
    public IPage<RuleAlarmList> pageList(RuleAlarmListVo vo) {
        IPage<RuleAlarmList> page = ruleAlarmListMapper.pageList(vo.page(),vo);
        List<RuleAlarmList> records = page.getRecords();
        records.forEach(alarmList -> {
            alarmList.setDataMap((Map) JSON.parse(alarmList.getAlarmData()));
        });
        page.setRecords(records);
        return page;
    }

    @Override
    public List<RuleAlarmList> list(RuleAlarmListVo vo) {
        List<RuleAlarmList> list =  ruleAlarmListMapper.list(vo);
        list.forEach(alarmList -> {
            alarmList.setDataMap((Map) JSON.parse(alarmList.getAlarmData()));
        });
        return list;
    }

    @Override
    public void insertAlarmInfo(RuleAlarmList alarmList) {
        ruleAlarmListMapper.insertAlarmInfo(alarmList);
    }

    @Override
    public Map<String,Object> dataStatistic(){
        return ruleAlarmListMapper.dataStatistic();
    }

    @Override
    public Map<String,Object> timeStatistic(){
        return ruleAlarmListMapper.timeStatistic();
    }
}
